<link rel="stylesheet" href="<%- Virtual_Path.Static %>main/css/profile.css"/>
<link rel="stylesheet" href="<%- Virtual_Path.Static %>main/css/common.css"/>
<div class="main-container">
    <div class="xiu-dialog" id="bd-password">
        <div class="divColorbox_Header" class="xiu-dialog-head">
            <span><i class="fa fa-star"></i><span>绑定手机号</span></span>
            <a class="Refresh"></a><a class="Close"></a>
        </div>
        <p class="valid-tip"></p>
        <div class="xiu-dialog-body">
            <div class="form-group">
                <label for="" class="form-label">
                    手机号:
                </label>
                <div class="form-hozinput">
                    <input type="text" name="Bound_QQWeiBo_Phone" class="form-control" placeholder="请输入手机号"/>
                </div>
            </div>
            <div class="form-group">
                <label for="" class="form-label">
                    验证码:
                </label>
                <div class="form-hozinput">
                    <input name="Bound_QQWeiBo_VerifyCode" type="text" class="form-control" style="width: 135px;"
                           placeholder="请输入验证码">
                    <a id="btnMainUser_Bound_PhoneVerifyCode_QQWeiBo" href="javascript:;"
                       class="getmobilecode Bound_qqweibo" name="1">获取验证码</a>
                </div>
            </div>
            <div class="form-group">
                <label for="" class="form-label">
                    设置密码:
                </label>
                <div class="form-hozinput">
                    <input type="password" name="newpwds" class="form-control" placeholder="请输入新密码"/>
                </div>
            </div>
            <div class="form-group">
                <label for="" class="form-label">
                    确认密码:
                </label>
                <div class="form-hozinput">
                    <input type="password" name="twonewpwds" class="form-control" placeholder="请再次输入新密码"/>
                </div>
            </div>
            <div class="form-group">
                <div class="form-hozinput form-hozinput-ml">
                    <input type="button" name="" class="form-button" value="提交" id="J_UserBoundWeiBo_sub"/>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        if (!_StateData.IsLogin) {
            $.CommonMain.Modal_Tip('请先登录', {Timeout: 1000});
            location.href = '/';
        }
        $("#bd-password").show();
        //发送验证码
        $('#btnMainUser_Bound_PhoneVerifyCode_QQWeiBo').click(function () {
            var _Button = $(this);
            if (_Button.hasClass('disable')) {
                return;
            }
            var _Phone =  $('input[name="Bound_QQWeiBo_Phone"]');
            var _PhoneNumber = _Phone.val();
            if (!(/^1\d{10}$/).test(_PhoneNumber)) {
                _Phone.focus();
                $.KOC.Tips.Open('Error', '请输入正确的手机号', {Timeout: 3000});
                return;
            }
            $.Common.PhoneVerifyCode.fnSend(_PhoneNumber, function () {
                //成功
                $.KOC.Tips.Open('Success', '验证短信已经发送至:' + _PhoneNumber + ',请注意查收', {Timeout: 2000});
                $.Common.PhoneVerifyCode.fnCountdown(function (Interval) {
                    _Button.addClass('disable');
                    if (Interval <= 0) {
                        _Button.removeClass('disable').text('重新获取验证码');
                    } else {
                        _Button.text(Interval + '秒后重新获取');
                    }
                });
            });
        });
        $('#J_UserBoundWeiBo_sub').on('click', function () {
            var params = {};
            var tel = /^0?(13[0-9]|15[012356789]|18[0123456789]|17[0123456789]|14[57])[0-9]{8}$|^[a-zA-Z0-9][a-zA-Z0-9._-]*\@[a-zA-Z0-9]+\.[a-zA-Z0-9\.]+$/;
            params.Phone = $.trim($('input[name="Bound_QQWeiBo_Phone"]').val());
            params.VerifyCode = $.trim($('input[name="Bound_QQWeiBo_VerifyCode"]').val());
            params.Password = $.trim($('input[name="newpwds"]').val());
            params.PasswordTwo = $.trim($('input[name="twonewpwds"]').val());
            if (!params.Phone) {
                $.CommonMain.Modal_Tip('请输入手机号', {Timeout: 2000});
                $('input[name="Bound_QQWeiBo_Phone"]').focus();
                return false;
            }
            if (!tel.test(params.Phone)) {
                $.CommonMain.Modal_Tip('你输入的手机号格式不正确', {Timeout: 2000});
                $('input[name="Bound_QQWeiBo_Phone"]').focus();
                return false;
            }
            if (!params.VerifyCode) {
                $.CommonMain.Modal_Tip('请输入你的验证码', {Timeout: 2000});
                $('input[name="Bound_QQWeiBo_VerifyCode"]').focus();
                return false;
            }
            if (!params.Password) {
                $.CommonMain.Modal_Tip('请输入新密码', {Timeout: 2000});
                $('input[name="newpwds"]').focus();
                return false;
            }
            if (!params.PasswordTwo) {
                $.CommonMain.Modal_Tip('请输入第二次新密码', {Timeout: 2000});
                $('input[name="twonewpwds"]').focus();
                return false;
            }
            if (params.PasswordTwo != params.Password) {
                $.CommonMain.Modal_Tip('你输入的两次密码不一致，请重新输入', {Timeout: 2000});
                $('input[name="newpwds"]').focus();
                return false;
            }
            if (params.Password.length < 4 || params.Password.length > 12) {
                $.CommonMain.Modal_Tip('请输入4～12字符密码', {Timeout: 2000});
                $('input[name="newpwds"]').focus();
                return false;
            }
            $.KOC.Loading.Open();
            $.ajax({
                url: '/ajax/user.user-info.updatephone',
                type: 'post',
                dataType: 'json',
                data: {
                    Phone: params.Phone,
                    VerifyCode: params.VerifyCode,
                    Password: md5(params.Password),
                    Type: 1
                },
                success: function (data) {
                    $.KOC.Loading.Close();
                    if (data.flag !== 0) {
                        $.CommonMain.Modal_Tip(data.msg + "(" + data.flag + ")", {Timeout: 2000});
                        return;
                    }
                    $.CommonMain.Modal_Tip('手机号绑定成功', {
                        Timeout: 1000,
                        onClose: function () {
                            $.Common.ModalWindow.fnEnter();
                        }
                    });
                }
            });
        });
    })
</script>